//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_x_xmarkervehicles.sqf"
#include "x_setup.sqf"

private "_rem";
_rem = [];
{
	if (!isNull _x && {alive _x}) then {
		_m = GV(_x,GVAR(marker));
		// TYRGHEN - We have problems with marker positions not updating, so I'm reverting to the old system.
		//_m setMarkerPosLocal (visiblePositionASL _x);
		_m setMarkerPosLocal (getPosASL _x);
		if (GVAR(v_marker_dirs)) then {
			_m setMarkerDirLocal (direction _x)
		};
		_cubh = if (_x isKindOf "Air") then {
			count ([_x] unitsBelowHeight 1) == 0
		} else {
			speed _x > 2
		};
		if (_cubh && {isNil {GV(_x,GVAR(mmtype))}}) then {
			_x setVariable [QGVAR(mmtype), markerType _m];
			_m setMarkerTypeLocal "mil_triangle";
			_mt = markerText _m;
			_x setVariable [QGVAR(mmtxt), _mt];
			_nt = _mt + ": ";
			_cttt = count (crew _x) - 1;
			{
				if (alive _x) then {
					_nt = _nt + (name _x);
					if (_forEachIndex < _cttt) then {
						_nt = _nt + ", ";
					};
				};
			} forEach (crew _x);
			_m setMarkerTextLocal _nt;
		} else {
			_mtt = GV(_x,GVAR(mmtype));
			if (!_cubh && {!isNil "_mtt"}) then {
				_m setMarkerTypeLocal _mtt;
				_x setVariable [QGVAR(mmtype), nil];
				_m setMarkerTextLocal GV(_x,GVAR(mmtxt));
				_x setVariable [QGVAR(mmtxt), nil];
			};
		};
		_m setMarkerAlphaLocal (if (!canMove _x) then {0.8} else {1.0});
	} else {
		_rem set [count _rem, _x];
		_mtt = GV(_x,GVAR(mmtype));
		if (!isNil "_mtt") then {
			_m setMarkerTypeLocal _mtt;
			_x setVariable [QGVAR(mmtype), nil];
			_m setMarkerTextLocal GV(_x,GVAR(mmtxt));
			_x setVariable [QGVAR(mmtxt), nil];
		};
	};
} forEach GVAR(marker_vecs);
if (count _rem > 0) then {GVAR(marker_vecs) = GVAR(marker_vecs) - _rem};